package ckw.network;

import java.io.Serializable;
import core.modules.Serializer;
import ckw.database.DatabaseManager;
import ckw.database.State;
import ckw.gui.MainWindowC;


public class StanC implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5331675428817910132L;
	private  boolean nasluchiwanie = false;
	private  boolean test = false;
	private  boolean wlaczony = false;
	private  int nrwiadomosci = 0;
	
	//zwraca kolejny numer wiadomosci
	public  synchronized int getNr(){
		nrwiadomosci++;
		DatabaseManager db = DatabaseManager.getInstance();
		State state = new State(nrwiadomosci, Serializer.OToS(this));
		db.saveState(state);	
		return nrwiadomosci;
	}
	
	public  synchronized boolean isNasluchiwanie() {
		return nasluchiwanie;
	}

	public  synchronized void setNasluchiwanie(boolean nasluchiwanie) {
		this.nasluchiwanie = nasluchiwanie;
		DatabaseManager db = DatabaseManager.getInstance();
		State state = new State(nrwiadomosci, Serializer.OToS(this));
		db.saveState(state);
		MainWindowC.changeState();
	}

	public  synchronized boolean isTest() {
		return test;
	}

	public  synchronized void setTest(boolean test) {
		this.test = test;
		DatabaseManager db = DatabaseManager.getInstance();
		State state = new State(nrwiadomosci, Serializer.OToS(this));
		db.saveState(state);
		MainWindowC.changeState();
	}

	public  synchronized boolean isWlaczony() {
		return wlaczony;
	}

	public  synchronized void setWlaczony(boolean wlaczony) {
		this.wlaczony = wlaczony;
		DatabaseManager db = DatabaseManager.getInstance();
		State state = new State(nrwiadomosci, Serializer.OToS(this));
		db.saveState(state);
		MainWindowC.changeState();
	}


}
